package scerbak.validation;

import java.util.Iterator;

import org.eclipse.xtext.validation.Check;

import scerbak.usecases.ActionStep;
import scerbak.usecases.UseCase;
import scerbak.usecases.UsecasesPackage;

public class UsecasesJavaValidator extends AbstractUsecasesJavaValidator {

	@Check
	public void orderOfSteps(final UseCase useCase) {
		final Iterator<ActionStep> iterator = useCase.getSteps().iterator();
		int previousOrdinal = 0;
		while (iterator.hasNext()) {
			final ActionStep step = iterator.next();
			final Integer nextOrdinal = Integer.valueOf(step.getName());
			if (nextOrdinal != previousOrdinal + 1) {
				error("Steps are not ordered properly, expected: "
						+ (previousOrdinal + 1) + " but was: " + nextOrdinal,
						UsecasesPackage.ACTION_STEP__NAME);
			}
			previousOrdinal = nextOrdinal;
		}
	}

}
